var mapOne=null;
var mapTwo=null;
var mapThr=null;
var mapFou=null;
var heatmapOverlayWeight;
var heatmapOverlayOverrun;
var heatmapOverlayTrain;
$(function(){
	var height=$("#mapOne").height();
	height=height/2;
	//alert(height);
	$("#mapOne").height(height);
	$("#mapTwo").height(height);
	$("#mapThr").height(height);
	$("#mapFou").height(height);
	mapOne = new BMap.Map("mapOne",{
		enableMapClick: false,
        minZoom : 4,
		maxZoom : 18
	});

	mapOne.centerAndZoom(new BMap.Point(116.236044, 36.14466), 4);
	//添加鼠标滚动缩放
	mapOne.enableScrollWheelZoom();
	heatmapOverlayWeight = new BMapLib.HeatmapOverlay({"radius":20});
	mapOne.addOverlay(heatmapOverlayWeight);

	mapTwo = new BMap.Map("mapTwo",{
		enableMapClick: false,
		minZoom : 4,
		maxZoom : 18
	});
	mapTwo.centerAndZoom(new BMap.Point(116.236044, 36.14466), 4);
	//添加鼠标滚动缩放
	mapTwo.enableScrollWheelZoom();
	heatmapOverlayOverrun = new BMapLib.HeatmapOverlay({"radius":20});
	mapTwo.addOverlay(heatmapOverlayOverrun);


	mapThr = new BMap.Map("mapThr",{
		enableMapClick: false,
		minZoom : 4,
		maxZoom : 18
	});
	mapThr.centerAndZoom(new BMap.Point(116.236044, 36.14466), 4);
	//添加鼠标滚动缩放
	mapThr.enableScrollWheelZoom();
	heatmapOverlayTrain = new BMapLib.HeatmapOverlay({"radius":20});
	mapThr.addOverlay(heatmapOverlayTrain);


	mapFou = new BMap.Map("mapFou",{
		enableMapClick: false,
		minZoom : 4,
		maxZoom : 18
	});
	mapFou.centerAndZoom(new BMap.Point(124.919833,36.14466), 4);
	//添加鼠标滚动缩放
	mapFou.enableScrollWheelZoom();
});
$(document).ready(function(){
	//cleanNowDataTimer();
	$(document).on('click', '.more-heat .heat-table input', function () {
		var type=$(this).val();
		HeatType=type;
		$('ul li span:contains("单图热力图")').parent().click();
		//$('.more-heat ul li span:contains("多图模式")').parent().click();
	});

	//$('.more-heat .heat-map-panel .easyui-tabs').tabs({
	//	onUnselect:function(){
	//		$('.more-heat ul li span:contains("多图模式")').parent().click();
	//	}
	//});
	//$('#moreTab').tabs('select', 1);
	initHeatWeightData();
	initHeatOverrunData();
	initHeatTrainData();
});

function initHeatWeightData(){
	var url=ctx+"/equipData/count?type=weight";
	$.ajax({
		url : url,
		data : {},
		dataType : 'json',
		type : 'get',
		success : function (data) {
			if(data.result){
				var stations=data.content;
				var points=new Array();
				var max=0;
				for(var i=0;i<stations.length;i++){
					var station=stations[i];
					var totalValue=station.totalValue;
					if(max<totalValue){
						max=totalValue;
					}
					var point={
						"lng":station.latitude,
						"lat":station.longitude,
						"count":station.totalValue
					}
					points.push(point);
				}
				heatmapOverlayWeight.setDataSet({data:points,max:max});
			}
		}
	})

}
function initHeatOverrunData(){
	var url=ctx+"/equipData/count?type=overrun";
	$.ajax({
		url : url,
		data : {},
		dataType : 'json',
		type : 'get',
		success : function (data) {
			if(data.result){
				var stations=data.content;
				var points=new Array();
				var max=0;
				for(var i=0;i<stations.length;i++){
					var station=stations[i];
					var totalValue=station.totalValue;
					if(max<totalValue){
						max=totalValue;
					}
					var point={
						"lng":station.latitude,
						"lat":station.longitude,
						"count":station.totalValue
					}
					points.push(point);
				}
				heatmapOverlayOverrun.setDataSet({data:points,max:max});
			}
		}
	})

}
function initHeatTrainData(){
	var url=ctx+"/equipData/count?type=train";
	$.ajax({
		url : url,
		data : {},
		dataType : 'json',
		type : 'get',
		success : function (data) {
			if(data.result){
				var stations=data.content;
				var points=new Array();
				var max=0;
				for(var i=0;i<stations.length;i++){
					var station=stations[i];
					var totalValue=station.totalValue;
					if(max<totalValue){
						max=totalValue;
					}
					var point={
						"lng":station.latitude,
						"lat":station.longitude,
						"count":station.totalValue
					}
					points.push(point);
				}
				heatmapOverlayTrain.setDataSet({data:points,max:max});
			}
		}
	})

}